package com.itbuka.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.itbuka.vip.domain.VipRechargeRecords;
import com.itbuka.vip.mapper.VipRechargeRecordsMapper;
import com.itbuka.vip.service.VipRechargeRecordsService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
 * @author ld
 * @description 针对表【vip_recharge_records】的数据库操作Service实现
 * @createDate 2024-07-29 17:28:03
 */
@Service
public class VipRechargeRecordsServiceImpl implements VipRechargeRecordsService {
    @Autowired
    private VipRechargeRecordsMapper vipRechargeRecordsMapper;

    @Override
    public List<VipRechargeRecords> selectAll() {
        LambdaQueryWrapper<VipRechargeRecords> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VipRechargeRecords::getIsDelete, 0);
        return vipRechargeRecordsMapper.selectList(lqw);
    }

    @Override
    public List<VipRechargeRecords> selectList(VipRechargeRecords vipRechargeRecords) {
        LambdaQueryWrapper<VipRechargeRecords> lqw = this.lqw(vipRechargeRecords);
        return vipRechargeRecordsMapper.selectList(lqw);
    }

    @Override
    public Integer insert(VipRechargeRecords vipRechargeRecords) {
        return vipRechargeRecordsMapper.insert(vipRechargeRecords);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                VipRechargeRecords vipRechargeRecords = new VipRechargeRecords();
                vipRechargeRecords.setId(Long.parseLong(id));
                vipRechargeRecords.setIsDelete(1);
                vipRechargeRecordsMapper.updateById(vipRechargeRecords);
            }
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }

    @Override
    public Integer update(VipRechargeRecords vipRechargeRecords) {
        return vipRechargeRecordsMapper.updateById(vipRechargeRecords);
    }

    @Override
    public Page<VipRechargeRecords> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return (Page<VipRechargeRecords>) this.selectAll();
    }

    @Override
    public Page<VipRechargeRecords> pageList(VipRechargeRecords vipRechargeRecords, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return (Page<VipRechargeRecords>) this.selectList(vipRechargeRecords);
    }

    public LambdaQueryWrapper<VipRechargeRecords> lqw(VipRechargeRecords vipRechargeRecords) {
        LambdaQueryWrapper<VipRechargeRecords> lqw = new LambdaQueryWrapper<>();
        if (vipRechargeRecords.getId() != null) {
            lqw.eq(VipRechargeRecords::getId, vipRechargeRecords.getId());
        }
        if (vipRechargeRecords.getVipName() != null) {
            lqw.eq(VipRechargeRecords::getVipName, vipRechargeRecords.getVipName());
        }
        if (vipRechargeRecords.getOrderNum() != null) {
            lqw.eq(VipRechargeRecords::getOrderNum, vipRechargeRecords.getOrderNum());
        }
        if (vipRechargeRecords.getRechargeMoney() != null) {
            lqw.eq(VipRechargeRecords::getRechargeMoney, vipRechargeRecords.getRechargeMoney());
        }
        if (vipRechargeRecords.getRechargeWay() != null) {
            lqw.eq(VipRechargeRecords::getRechargeWay, vipRechargeRecords.getRechargeWay());
        }
        if (vipRechargeRecords.getPayStatus() != null) {
            lqw.eq(VipRechargeRecords::getPayStatus, vipRechargeRecords.getPayStatus());
        }
        if (vipRechargeRecords.getRechargeTime() != null) {
            lqw.eq(VipRechargeRecords::getRechargeTime, vipRechargeRecords.getRechargeTime());
        }
        if (vipRechargeRecords.getPayTime() != null) {
            lqw.eq(VipRechargeRecords::getPayTime, vipRechargeRecords.getPayTime());
        }
        if (vipRechargeRecords.getIsDelete() != null) {
            lqw.eq(VipRechargeRecords::getIsDelete, vipRechargeRecords.getIsDelete());
        }
        if (vipRechargeRecords.getCreateTime() != null) {
            lqw.eq(VipRechargeRecords::getCreateTime, vipRechargeRecords.getCreateTime());
        }
        if (vipRechargeRecords.getUpdateTime() != null) {
            lqw.eq(VipRechargeRecords::getUpdateTime, vipRechargeRecords.getUpdateTime());
        }
        return lqw;
    }
}




